package com.heima.homeservicemanagementsystem.module;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * @Description
 * @Author jcf
 * @Date 2025/3/30
 */
@Slf4j
public class idNumberJsonSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
//        log.info("用户身份证：{}", value);
        if (value != null && value.length() == 18) {
            String replace = value.replaceAll("(\\d{6})\\d{8}(\\d{4})", "$1********$2");
            gen.writeString(replace);
            return;
        }
        gen.writeNull();
    }
}
